#!/usr/local/bin/python
# -*- encoding:utf-8 -*-
''''This Script is designed to do the trick opimized with column vector'''

import numpy as np;
import scipy.sparse as sp
from scipy import linalg
import time
import threading
import os
from scipy.sparse.linalg import eigsh
from multiprocessing import Process, Manager
import sys
import utils


bm25_unmatch_statistical = open('bm25_unmatch_statistical', 'r');

bm25_dict = {}
for line in bm25_unmatch_statistical:
	li = line.strip().split('\t', 2);
	log = li[2];

	query = log.split('|',1)[0];
	clickN = int(li[1]);
	union = float(li[0]);
	if bm25_dict.has_key(query):
		print 'Wrong';
	else:
		bm25_dict[query] =(union, clickN)

bm25_unmatch_statistical.close();

sort_dict = {};
sort_results = open('sortResults', 'r');

for line in sort_results:
	li = line.strip().split('\t');
	sc = float(li[0]);
	query = li[2];
	if sort_dict.has_key(query):
		print 'wrong';
	else:
		sort_dict[query] = sc;

sort_results.close();

def  computeBy3(sc, union, clickN):
	if union > 0:
		return False;
	if sc > 15 or sc < 0:
		return False;
	if clickN < 10:
		return False;

	return True;

def  computeBy1(sc):
	if sc > 15:
		return False;
	return True;
for query, sc in sort_dict.items():
	
	if  bm25_dict.has_key(query):
		union, clickN = bm25_dict[query]
		if computeBy3(sc, union, clickN):
			print '%s:%f:%f:%d' %(query, sc, union, clickN);
	else:
		if computeBy1(sc):
			pass;
            #print query, sc;
	
